//
//  SISSPassenerProgerssManageCell.m
//  SISSAPP
//
//  Created by 优房网 on 2017/4/19.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSPassengerProgerssManageCell.h"


@interface SISSPassengerProgerssManageCell ()

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *detailLabel;
@property (weak, nonatomic) IBOutlet UILabel *progressTagLabel;
@property (weak, nonatomic) IBOutlet UILabel *trustCountLabel;
@property (weak, nonatomic) IBOutlet UILabel *trustMethodLabel;
@property (weak, nonatomic) IBOutlet UIButton *redDotButton;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *trustCountHeightConstraint;

@end
@implementation SISSPassengerProgerssManageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    // 设置委托人数边框
    self.trustCountLabel.layer.borderWidth = 1;
    self.trustCountLabel.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor;
    self.trustCountLabel.layer.cornerRadius = 4;
    self.trustCountLabel.layer.masksToBounds = YES;
    
    // 设置委托方式边框
    self.trustMethodLabel.layer.borderWidth = 1;
    self.trustMethodLabel.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor;
    self.trustMethodLabel.layer.cornerRadius = 4;
    self.trustMethodLabel.layer.masksToBounds = YES;
}

- (void)setIsHistory:(BOOL)isHistory {
    _isHistory = isHistory;
    self.trustCountLabel.hidden = isHistory;
    self.trustMethodLabel.hidden = isHistory;
    self.trustCountHeightConstraint.constant = isHistory ? 0.01 : 20;
}

- (void)setPassengerProgressModel:(SISSPassengerProgressModel *)passengerProgressModel {
    _passengerProgressModel = passengerProgressModel;
    
    // 根据身份证判断显示 先生、女士
    NSString *fisrtName = passengerProgressModel.name.length > 0 ? [passengerProgressModel.name substringToIndex:1] : @"";
    NSInteger idNum = [[passengerProgressModel.idNumber substringWithRange:NSMakeRange(passengerProgressModel.idNumber.length - 2, 1)] integerValue];
    NSString *genderStr = (idNum % 2) == 0 ? @"女士" : @"先生";
    self.nameLabel.text = [NSString stringWithFormat:@"%@%@",fisrtName,genderStr];
    self.detailLabel.text = [NSString stringWithFormat:@"%0.f-%0.f万 | %@-%@ | %@",passengerProgressModel.demand.minPrice,passengerProgressModel.demand.maxPrice,passengerProgressModel.demand.region,passengerProgressModel.demand.regionDetail,passengerProgressModel.demand.houseType];
    self.trustCountLabel.text = [NSString stringWithFormat:@"委托人数：%zd",passengerProgressModel.entrustCount];

    self.trustMethodLabel.hidden = (passengerProgressModel.entrustType != 2) || self.isHistory;

    self.trustMethodLabel.text = passengerProgressModel.entrustType == 2 ? @"定向委托" : @"";
    self.redDotButton.hidden = !passengerProgressModel.has_news;
    NSArray *entrustArr = @[@"上传委托合同", @"上传委托合同", @"实地看房", @"上传购房资格表", @"确定购买房源", @"上传买家告知书", @"上传卖家告知书", @"上传居间合同", @"上传买卖合同", @"系统核验网签合同", @"服务评价", @"已完成"];
    
    NSInteger count = self.isHistory ? 2 : 1;
    if (passengerProgressModel.progress >= 11) {
        count = 1;
    }
//    NSInteger index = (passengerProgressModel.progress - count) > 10 ? 10 : (passengerProgressModel.progress - count);
    NSInteger index = passengerProgressModel.progress - count;
    self.progressTagLabel.text = entrustArr[index];
}

@end
